
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 08/26/2016 13:48:32
-- Generated from EDMX file: C:\Users\LLiangShaoTian\Desktop\mvc\Ebook\Ebooks.Models\Ebook.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Ebook];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Admin]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Admin];
GO
IF OBJECT_ID(N'[dbo].[AdminLog]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AdminLog];
GO
IF OBJECT_ID(N'[dbo].[Book]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Book];
GO
IF OBJECT_ID(N'[dbo].[Customer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Customer];
GO
IF OBJECT_ID(N'[dbo].[DownloadLog]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DownloadLog];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Admins'
CREATE TABLE [dbo].[Admins] (
    [Id] int  NOT NULL,
    [AdminName] varchar(100)  NOT NULL,
    [password] varchar(100)  NOT NULL,
    [RegisterTime] datetime  NOT NULL
);
GO

-- Creating table 'AdminLogs'
CREATE TABLE [dbo].[AdminLogs] (
    [Id] int  NOT NULL,
    [AdminId] int  NOT NULL,
    [AdminName] varchar(100)  NULL,
    [Events] varchar(200)  NULL,
    [CreateTime] datetime  NOT NULL,
    [AdminIp] varchar(100)  NOT NULL
);
GO

-- Creating table 'Books'
CREATE TABLE [dbo].[Books] (
    [Id] int  NOT NULL,
    [BookName] varchar(100)  NOT NULL,
    [Author] varchar(100)  NULL,
    [Formatting] varchar(100)  NOT NULL,
    [Publisher] varchar(100)  NULL,
    [UnloadId] int  NOT NULL,
    [Descriptions] varchar(1000)  NULL,
    [DounloadTotal] int  NOT NULL,
    [OnloadTime] datetime  NOT NULL,
    [EndTime] datetime  NOT NULL,
    [FirstLevel] varchar(100)  NULL,
    [SecondLevel] varchar(100)  NULL,
    [Price] decimal(18,0)  NOT NULL,
    [Img] varchar(200)  NULL,
    [ResourceUrl] varchar(100)  NULL
);
GO

-- Creating table 'Customers'
CREATE TABLE [dbo].[Customers] (
    [Id] int  NOT NULL,
    [CustomerName] varchar(100)  NOT NULL,
    [Email] varchar(100)  NULL,
    [password] varchar(100)  NULL,
    [RegisterTime] datetime  NOT NULL,
    [Points] decimal(18,0)  NOT NULL
);
GO

-- Creating table 'DownloadLogs'
CREATE TABLE [dbo].[DownloadLogs] (
    [Id] int  NOT NULL,
    [BookId] int  NOT NULL,
    [DownloadName] varchar(100)  NULL,
    [DownloadId] int  NOT NULL,
    [BookName] varchar(100)  NULL,
    [DownloadTime] datetime  NOT NULL,
    [UserIp] varchar(100)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Admins'
ALTER TABLE [dbo].[Admins]
ADD CONSTRAINT [PK_Admins]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'AdminLogs'
ALTER TABLE [dbo].[AdminLogs]
ADD CONSTRAINT [PK_AdminLogs]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Books'
ALTER TABLE [dbo].[Books]
ADD CONSTRAINT [PK_Books]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Customers'
ALTER TABLE [dbo].[Customers]
ADD CONSTRAINT [PK_Customers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DownloadLogs'
ALTER TABLE [dbo].[DownloadLogs]
ADD CONSTRAINT [PK_DownloadLogs]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------